package assignmentstrategy

import (
	"codejy/analysis/codeanalysis"
	"codejy/store"
	"codejy/structdef"
	"strings"
)

type ThisPropStrategy struct {
}

func init() {
	RegisterStrategy(&ThisPropStrategy{})
}
func (n ThisPropStrategy) getId() int {
	return codeanalysis.ThisProp
}

func (n ThisPropStrategy) Execute(threadStore *structdef.ThreadStore, code string) string {
	currentInstanceAddress := threadStore.CurrentInstanceAddress
	prop, _ := store.GetInstanceProp(threadStore, currentInstanceAddress)
	index := strings.Index(code, ".")
	propName := code[index+1:]
	definition, p := prop[propName]
	typeName, _ := prop["@TYPENAME@"] //获取实例的类型名称
	if p {
		return definition.Value
	} else {
		panic("错误::::::" + typeName.Value + "类型中没有" + code + "的成员变量定义")
	}
}
